package leetcode.hot100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ThreeSum {
    public static void main(String[] args) {
        int[] nums = {-1, 0, 1, 2, -1, -4};
        List<List<Integer>> res = new ThreeSum().threeSum(nums);
        System.out.println(res);
    }

    public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        int len = nums.length;
        int i = 0;
        int j = len - 1;
        if (len < 3) {
            return res;
        }
        Arrays.sort(nums);
        while (i < j) {
            List<Integer> tem = new ArrayList<>();
            for (int k = i + 1; k < j; k++) {
                if (nums[k] + nums[i] + nums[j] == 0) {
                    tem.add(nums[i]);
                    tem.add(nums[k]);
                    tem.add(nums[j]);
                    res.add(tem);
                }
            }
            if (nums[i+1]==nums[i]){

            }
            i++;
            j--;
        }

        return res;
    }
}
